package vn.edu.ptithcm.pim.service;

import vn.edu.ptithcm.pim.constant.Constants;
import vn.edu.ptithcm.pim.dom.User;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import vn.edu.ptithcm.pim.dao.UserDao;

@SuppressWarnings({ "rawtypes" })
public class UserService {
	private UserDao userDao;

	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	public void save(User user) {
		userDao.save(user);
	}

	public void saveOrUpdate(User user) {
		userDao.saveOrUpdate(user);
	}

	public void lock(User user) {
		userDao.lock(user);
	}

	public void delete(User user) {
		userDao.delete(user);
	}

	public User merge(User user) {
		return userDao.merge(user);
	}

	public User findById(java.lang.Long id) {
		return userDao.findById(id);
	}

	public List findByExample(User user) {
		return userDao.findByExample(user);
	}

	public List getAll() {
		return userDao.getAll();
	}

	public User findByLoginName(String loginname) {
		return userDao.findByLoginName(loginname);
	}

	public boolean isLogin(String loginname, String password, Object salt) {
		return userDao.isLogin(loginname, password, salt);
	}

	public boolean isAdmin(String loginname) {
		return userDao.isAdmin(loginname);
	}

	public boolean isSignedIn(HttpServletRequest request) {
		String loginName = (String) request.getSession().getAttribute(
				Constants.LOGIN_NAME);
		return loginName != null ? true : false;
	}

	public String getCurrentLogin(HttpServletRequest request) {
		String loginName = (String) request.getSession().getAttribute(
				Constants.LOGIN_NAME);
		return loginName;
	}

	public String getUsername(String loginname) {
		return userDao.getUsername(loginname);
	}

	public String getVisa(String loginname) {
		return userDao.getVisa(loginname);
	}

	public List getApplications(String loginname) {
		return userDao.getApplications(loginname);
	}

	public int getPermisionOfUserInApplication(String loginname,
			java.lang.Long applicationId) {
		return userDao
				.getPermisionOfUserInApplication(loginname, applicationId);
	}

	public boolean changePassword(String loginName, String oldPass,
			String newPass, Object salt) {
		return userDao.changePassword(loginName, oldPass, newPass, salt);
	}

	public String resetPassword(String email, Object salt) {
		return userDao.resetPassword(email, salt);
	}

	public User findByEmail(String email) {
		return userDao.findByEmail(email);
	}
}
